<template>
  <div class="home">
    <el-menu
      :default-active="activeIndex2"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <el-menu-item index="1">
        <router-link :to="{ name: 'Home' }">Home</router-link>
      </el-menu-item>
      <el-menu-item index="2">
        <router-link :to="{ name: 'About' }">关于我们</router-link>
      </el-menu-item>
      <el-menu-item index="3" disabled>消息中心</el-menu-item>
      <el-menu-item index="4"
        ><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item
      >
    </el-menu>

    <el-row>
      <el-col :span="16" :lg="16" :md="16" :sm="16" :xs="16">
        <el-carousel
          :interval="4000"
          type="card"
          height="400px"
          v-loading="isLoading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
        >
          <el-carousel-item v-for="(item, index) in bannerList" :key="index">
            <img class="banner-item" :src="item.image" alt="" />
          </el-carousel-item>
        </el-carousel>
      </el-col>
      <el-col
        class="hidden-sm-and-down"
        :span="8"
        :lg="8"
        :md="8"
        :sm="8"
        :xs="8"
      >
        <div style="background: red" class="grid-content bg-purple-dark">
          col 12
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "Home",
  data() {
    return {
      activeIndex2: "1",
      bannerList: [],
      isLoading: false,
    };
  },
  created() {
    // console.log(process.env.NODE_ENV);
    this.isLoading = true;
    axios({
      method: "GET",
      url: "https://gank.io/api/v2/banners",
    })
      .then((res) => {
        this.bannerList = res.data.data;
        console.log(res.data.data);
      })
      .catch(() => {
        this.$message.error("网络错误，请刷新重试");
      })
      .finally(() => {
        this.isLoading = false;
      });
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

<style lang="stylus">

.banner-item
  object-fit cover
  height 100%
  width 100%

.el-row {
  margin-bottom: 20px;
  &:last-child {
     margin-bottom: 0;
   }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
  border: 2px solid #000;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
